/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package chatsystem;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 * @deprecated 
 * @author morrison
 */
public class ConnectionPanel extends JPanel {

    private Controller control;

    private final JTextField username;
    private JLabel usernameLabel;
    private JButton btn;

    
    private void btnConnect() {
        this.control.connect(username.getText());
    }
    
    public ConnectionPanel(Controller control) {

        super();
        this.control = control;
        
        //Ajout du layout à la JFrame
        this.setLayout(new GridBagLayout());
        GridBagConstraints c = new GridBagConstraints();

        /*JMenuBar barre = new JMenuBar();
        barre.add(new JMenu("Kikoo").add(new JMenuItem("salut")));
        c.gridy = 3;
        c.fill = GridBagConstraints.HORIZONTAL;
        //c.anchor = GridBagConstraints.LAST_LINE_START;
        p.add(barre, c);
         */

        //Création de la petite zone texte :
        usernameLabel = new JLabel("Username");
        c.fill = GridBagConstraints.NONE;
        c.gridx = 0;
        c.gridy = 0;
        c.insets.set(10, 10, 3, 10);
        //c.anchor=GridBagConstraints.LAST_LINE_END;
        this.add(usernameLabel, c);


        //Création de la zone de saisie :
        username = new JTextField();
        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridx = 0;
        c.gridy = 1;
        c.weightx = 0.8;
        c.weighty = 0.0;
        c.insets.set(3, 15, 3, 15);
        //c.anchor=GridBagConstraints.CENTER;
        this.add(username, c);

        //Création de la zone du bouton
        btn = new JButton("Connect");
        btn.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent ae) {
                btnConnect();
            }
        });
        c.fill = GridBagConstraints.NONE;
        //c.anchor=GridBagConstraints.CENTER;
        c.gridx = 0;
        c.gridy = 2;
        c.gridwidth = 2;
        c.ipadx = 32;
        c.ipady = 14;
        c.weightx = 0.0;
        c.weighty = 0.0;
        c.insets.set(3, 10, 10, 10);
        this.add(btn, c);

        this.setPreferredSize(new Dimension(260, 345));
    }
}